<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <meta name="referrer" content="no-referrer-when-downgrade">
    

    <title>Vue_cli相关vuex以及Router | 早起的年轻人</title>
    <meta property="og:title" content="Vue_cli相关vuex以及Router - 早起的年轻人">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2021-09-16T13:57:48&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2021-09-16T13:57:48&#43;08:00'>
        
    <meta name="Keywords" content="Flutter，golang,go语言,go语言笔记,飞雪无情,java,android,博客,项目管理,python,软件架构,公众号,小程序">
    <meta name="description" content="Vue_cli相关vuex以及Router">
        
    <meta name="author" content="luckly">
    <meta property="og:url" content="https://luckly.work/post/vue/Vue_cli%E7%9B%B8%E5%85%B3vuex%E4%BB%A5%E5%8F%8ARouter/">
    <link rel="shortcut icon" href='/favicon.ico'  type="image/x-icon">

    <link rel="stylesheet" href='/css/normalize.css'>
    <link rel="stylesheet" href='/css/style.css'>
    <script type="text/javascript" src="//cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    
    
        <link href="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" rel="stylesheet">
    
    
    
    
        <link rel="stylesheet" href='/css/douban.css'>
    
        <link rel="stylesheet" href='/css/other.css'>
    
</head>

<link rel="stylesheet"
      href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/highlight.min.js"></script>
<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://luckly.work/">
                        早起的年轻人
                    </a>
                
                <p class="description">专注于Flutter、Android、Java、Go语言(golang)、移动互联网、项目管理、软件架构</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://luckly.work/">首页</a>
                    
                    <a  href="https://luckly.work/categories/" title="分类">分类</a>
                    
                    <a  href="https://luckly.work/tags/" title="标签">标签</a>
                    
                    <a  href="https://luckly.work/archives/" title="归档">归档</a>
                    
                    <a  href="https://luckly.work/about/" title="关于我">关于我</a>
                    
                    <a  href="https://github.com/ITmxs/" title="github">github</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    <style type="text/css">
    .post-toc {
        position: fixed;
        width: 200px;
        margin-left: -210px;
        padding: 5px 10px;
        font-family: Athelas, STHeiti, Microsoft Yahei, serif;
        font-size: 12px;
        border: 1px solid rgba(0, 0, 0, .07);
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 0.98);
        background-clip: padding-box;
        -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        word-wrap: break-word;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 999;
        cursor: pointer;
        max-height: 70%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .post-toc .post-toc-title {
        width: 100%;
        margin: 0 auto;
        font-size: 20px;
        font-weight: 400;
        text-transform: uppercase;
        text-align: center;
    }

    .post-toc .post-toc-content {
        font-size: 15px;
    }

    .post-toc .post-toc-content>nav>ul {
        margin: 10px 0;
    }

    .post-toc .post-toc-content ul {
        padding-left: 20px;
        list-style: square;
        margin: 0.5em;
        line-height: 1.8em;
    }

    .post-toc .post-toc-content ul ul {
        padding-left: 15px;
        display: none;
    }

    @media print,
    screen and (max-width:1057px) {
        .post-toc {
            display: none;
        }
    }
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
        <nav id="TableOfContents">
  <ul>
    <li><a href="#你能学到什么">你能学到什么</a></li>
    <li><a href="#vue-cli3-搭建前置">Vue-cli3 搭建前置</a></li>
    <li><a href="#ui-图形化配置界面">ui 图形化配置界面</a></li>
    <li><a href="#vue-文件的基本结构">.vue 文件的基本结构</a></li>
    <li><a href="#vue-router">Vue-Router</a></li>
    <li><a href="#vue-router-的子路由">vue-router 的子路由</a></li>
    <li><a href="#vue-router-传参">vue-router 传参</a></li>
    <li><a href="#vuex">vuex</a></li>
    <li><a href="#state-属性">state 属性</a></li>
    <li><a href="#getters-属性">getters 属性</a></li>
    <li><a href="#mutations">mutations</a></li>
    <li><a href="#actions-属性">actions 属性</a></li>
    <li><a href="#modules">modules</a></li>
  </ul>
</nav>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var postToc = $(".post-toc");
        if (postToc.length) {
            var leftPos = $("#main").offset().left;
            if(leftPos<220){
                postToc.css({"width":leftPos-10,"margin-left":(0-leftPos)})
            }

            var t = postToc.offset().top - 20,
                a = {
                    start: {
                        position: "absolute",
                        top: t
                    },
                    process: {
                        position: "fixed",
                        top: 20
                    },
                };
            $(window).scroll(function () {
                var e = $(window).scrollTop();
                e < t ? postToc.css(a.start) : postToc.css(a.process)
            })
        }
    })
</script>
    <article class="post">
        <header>
            <h1 class="post-title">Vue_cli相关vuex以及Router</h1>
        </header>
        <date class="post-meta meta-date">
            2021年9月16日
        </date>
        
        <div class="post-meta">
            <span>|</span>
            
            <span class="meta-category"><a href='/categories/Vue'>Vue</a></span>
            
        </div>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="post-content">
            <h1 id="vue-cli3-vuex-vue-router">Vue-cli3 Vuex Vue-router</h1>
<h2 id="你能学到什么">你能学到什么</h2>
<p>在这一期的学习进度中，我们会开始学习在我们工作开发中真正要使用的开发模式，vue-cli3 脚手架的运用以及 Vue-router 和状态管理仓 Vuex</p>
<h2 id="vue-cli3-搭建前置">Vue-cli3 搭建前置</h2>
<p><strong>安装 node 环境</strong></p>
<p>因为 Vue-cli3 也是基于 webpack 搭建的，所以我们还是必须要用到 node，如果你的电脑还没有安装 node 的话，可以到 node 官网自行下载安装，<a href="https://bbs.gin-vue-admin.com/redirect?url=https%3A%2F%2Fnodejs.org%2Fzh-cn%2F">https://nodejs.org/zh-cn/</a> 推荐大家下载 10.14.0 版本。 安装过后 到命令行执行 node -v 检查版本，如果弹出版本 v10.14.0 的话 恭喜你 安装成功，我们开始进行下面的步骤了。</p>
<p><strong>全局安装 vue-cli3</strong>
Vue CLI 的包名称由 vue-cli 改成了 @vue/cli。 如果你已经全局安装了旧版本的 vue-cli (1.x 或 2.x)，你需要先通过 npm uninstall vue-cli -g 卸载它。</p>
<p>官方要求安装的 node 版本是大于 8.9 的，我们安装的 node 为 10.14.0，如果你本身的版本低于 8.9 那么可以用 nvm 进行升级</p>
<p>然后我们到命令行执行</p>
<pre><code>npm install -g @vue/cli
</code></pre><p>等待运行完毕，我们命令行执行</p>
<pre><code>vue --version
</code></pre><p>如果版本在 3.0 以上，恭喜你安装成功了</p>
<p>接下来我们在命令行运行</p>
<pre><code>vue create hello-world
</code></pre><p>这时候它会提醒我们来选择需要安装的选项</p>
<pre><code>Vue CLI v3.1.3
┌───────────────────────────┐
│  Update available: 3.2.1  │
└───────────────────────────┘
? Please pick a preset: (Use arrow keys)
&gt; my (vue-router, vuex, less, babel, eslint)
  default (babel, eslint)
  Manually select features
</code></pre><p>第一个是我已经保存过的了，我们初次搭建，选择 Manually select features</p>
<pre><code>Vue CLI v3.1.3
┌───────────────────────────┐
│  Update available: 3.2.1  │
└───────────────────────────┘
? Please pick a preset: Manually select features
? Check the features needed for your project: (Press &lt;space&gt; to select, &lt;a&gt; to toggle all, &lt;i&gt; to invert selection)
&gt;( ) Babel
 ( ) TypeScript
 ( ) Progressive Web App (PWA) Support
 ( ) Router
 ( ) Vuex
 ( ) CSS Pre-processors
 ( ) Linter / Formatter
 ( ) Unit Testing
 ( ) E2E Testing
</code></pre><p>我们看到如上界面以后，选择 Babel Router Vuex CSS Pre-processors （使用空格键选中） 进行下一步</p>
<pre><code>Vue CLI v3.1.3
┌───────────────────────────┐
│  Update available: 3.2.1  │
└───────────────────────────┘
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS
? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In package.json
? Save this as a preset for future projects? Yes
? Save preset as: MyTest
</code></pre><p>接下来大家按照如上配置，基本可以完成项目搭建。等待安装完毕后执行</p>
<pre><code> 
cd helloworld
npm run serve
 
</code></pre><p>进入浏览器 打开 localhost:8080 如果看到 Vue 的欢迎界面，恭喜你，我们已经迈出成功第一步了</p>
<h2 id="ui-图形化配置界面">ui 图形化配置界面</h2>
<p>在 Vue-cli3 中 为大家提供了图形化配置界面 执行</p>
<pre><code> 
vue ui 
 
</code></pre><p>会开到提示在 localhost:8000 打开了 UI 配置界面，由于个人感觉图形化配置还是不灵活的，这里就先不给大家做太多演示了，要想做好一个 VUE 项目，需要做太多的搭配，我这里会配置一套基本可以使用的 VUE 框架放到个人 GitHub 供大家使用。</p>
<h2 id="vue-文件的基本结构">.vue 文件的基本结构</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html">&lt;<span style="color:#f92672">template</span>&gt;
  <span style="color:#75715e">&lt;!-- 这里面写html --&gt;</span>
&lt;/<span style="color:#f92672">template</span>&gt;
 
&lt;<span style="color:#f92672">script</span>&gt;
<span style="color:#75715e">// 如果要引入外部的文件 请在 export default外面引入
</span><span style="color:#75715e">// 例如  // @ is an alias to /src
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">HelloWorld</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;@/components/HelloWorld.vue&#39;</span>  <span style="color:#75715e">//这里引入了 HelloWorld组件
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> {
  <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;home&#39;</span>,
  <span style="color:#a6e22e">components</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">HelloWorld</span>  <span style="color:#75715e">//使用组件
</span><span style="color:#75715e"></span>  }
}
<span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> {
  <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;vue&#39;</span>, <span style="color:#75715e">//这里面就写VUE组件内的属性即可
</span><span style="color:#75715e"></span>}
 
&lt;/<span style="color:#f92672">script</span>&gt;
 
&lt;<span style="color:#f92672">style</span>&gt;
<span style="color:#75715e">/* 这里写css 当然你也可以写 lass scss 需要babel支持并且在 style上添加 lang属性 例如   &lt;style lang=&#34;scss&#34;&gt; */</span>
&lt;/<span style="color:#f92672">style</span>&gt;
</code></pre></div><h2 id="vue-router">Vue-Router</h2>
<p>我们使用 VUE 一般是用来开发单页程序，那么在单页程序内的跳转就要用到路由的形式，由于这里课程是要带大家快速熟悉 VUE 并且使用 VUE，所以原理这里暂且跳过，直接告诉大家使用方法。
我们在开始选择框架要用到的东西的时候已经选择了 Vue-Router，这里我们直接上代码使用即可。我们这里就搭配着 Vue-Cli3 的脚手架来讲解，这里顺便为大家讲解一下 Vue-cli3 脚手架为我们创建的目录结构</p>
<p>│ .gitignore Git 屏蔽提交文件
│ babel.config.js 自定义 babel 的地方
│ package.json 你的所有依赖啥的
│ README.md 不介绍
│ yarn.lock yarn 如果你是 npm 就是 package-lock.json
│
├─public 通过执行 npm run build 产生
│ favicon.ico
│ index.html
│
└─src 主要我们要修改的地方
│ App.vue App 主组件
│ main.js 入口 JS
│ router.js 路由文件
│ store.js vueX store 文件
│
├─assets 静态文件存放处
│ logo.png
│
├─components 我们自己写的组件
│ HelloWorld.vue
│
└─views VUE 页面，这么安排为了方便区分是组件还是用于路由跳转的页面
About.vue
Home.vue</p>
<p>我们直接看到入口文件</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">// main.js
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">App</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;./App.vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">router</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;./router&#39;</span>   <span style="color:#75715e">//在入口文件引用了router 并且 在newVue的时候 把router挂在到了router属性上
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">store</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;./store&#39;</span>
 
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">config</span>.<span style="color:#a6e22e">productionTip</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">false</span>
 
<span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Vue</span>({
  <span style="color:#a6e22e">router</span>,   <span style="color:#75715e">// 挂载
</span><span style="color:#75715e"></span>  <span style="color:#a6e22e">store</span>,
  <span style="color:#a6e22e">render</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">h</span> =&gt; <span style="color:#a6e22e">h</span>(<span style="color:#a6e22e">App</span>)
}).<span style="color:#a6e22e">$mount</span>(<span style="color:#e6db74">&#39;#app&#39;</span>)
 
</code></pre></div><p>接着我们看到 router.js 文件</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">//router.js
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Router</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue-router&#39;</span>  <span style="color:#75715e">//这里引用了vue-router 并且用Vue.use来使用Router
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Home</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;./views/Home.vue&#39;</span>
 
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Router</span>)
 
<span style="color:#75715e">// Router的内置属性
</span><span style="color:#75715e"></span><span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Router</span>({
  <span style="color:#a6e22e">mode</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;history&#39;</span>,  <span style="color:#75715e">//要使用hash模式还是 history模式 我们一般情况下还是用 hash模式 history在后台支持的情况下可以开启
</span><span style="color:#75715e"></span>  <span style="color:#a6e22e">base</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">process</span>.<span style="color:#a6e22e">env</span>.<span style="color:#a6e22e">BASE_URL</span>,  <span style="color:#75715e">// 应用的基路径。例如，如果整个单页应用服务在 /app/ 下，然后 base 就应该设为 &#34;/app/&#34;
</span><span style="color:#75715e"></span>  <span style="color:#a6e22e">routes</span><span style="color:#f92672">:</span> [              <span style="color:#75715e">//这就是真正写路由的地方了 
</span><span style="color:#75715e"></span>    {
      <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/&#39;</span>,        <span style="color:#75715e">//  当路由是/的时候 我们匹配哪个组件(这里是Home.vue)
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;home&#39;</span>,
      <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">Home</span>
    },
    {
      <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/about&#39;</span>,   <span style="color:#75715e">//  当路由是/about的时候 我们匹配哪个组件(About.vue)
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;about&#39;</span>,
      <span style="color:#75715e">// route level code-splitting
</span><span style="color:#75715e"></span>      <span style="color:#75715e">// this generates a separate chunk (about.[hash].js) for this route
</span><span style="color:#75715e"></span>      <span style="color:#75715e">// which is lazy-loaded when the route is visited.
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> () =&gt; <span style="color:#66d9ef">import</span>(<span style="color:#75715e">/* webpackChunkName: &#34;about&#34; */</span> <span style="color:#e6db74">&#39;./views/About.vue&#39;</span>)   <span style="color:#75715e">//路游懒加载，推荐使用这种模式，不过我们需要改写一下
</span><span style="color:#75715e"></span>    }
  ]
})
 
</code></pre></div><p>稍微做一下懒加载模式的改写</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">//router.js
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Router</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue-router&#39;</span>  <span style="color:#75715e">//这里引用了vue-router 并且用Vue.use来使用Router
</span><span style="color:#75715e"></span>
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Router</span>)
 
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">Home</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/Home.vue&#39;</span>)   <span style="color:#75715e">//使用常量模式 提前声明 并且在component中使用 这样我们就完成了一个可以简单实用的路由了
</span><span style="color:#75715e"></span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">About</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/About.vue&#39;</span>)
 
 
<span style="color:#75715e">// Router的内置属性
</span><span style="color:#75715e"></span><span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Router</span>({
  <span style="color:#a6e22e">mode</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;history&#39;</span>,  <span style="color:#75715e">//要使用hash模式还是 history模式 我们一般情况下还是用 hash模式 history在后台支持的情况下可以开启
</span><span style="color:#75715e"></span>  <span style="color:#a6e22e">base</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">process</span>.<span style="color:#a6e22e">env</span>.<span style="color:#a6e22e">BASE_URL</span>,  <span style="color:#75715e">// 应用的基路径。例如，如果整个单页应用服务在 /app/ 下，然后 base 就应该设为 &#34;/app/&#34;
</span><span style="color:#75715e"></span>  <span style="color:#a6e22e">routes</span><span style="color:#f92672">:</span> [              <span style="color:#75715e">//这就是真正写路由的地方了 
</span><span style="color:#75715e"></span>    {
      <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/&#39;</span>,        <span style="color:#75715e">//  当路由是/的时候 我们匹配哪个组件(这里是Home.vue)
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;home&#39;</span>,
      <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">Home</span>
    },
    {
      <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/about&#39;</span>,   <span style="color:#75715e">//  当路由是/about的时候 我们匹配哪个组件(About.vue)
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;about&#39;</span>,
      <span style="color:#75715e">// route level code-splitting
</span><span style="color:#75715e"></span>      <span style="color:#75715e">// this generates a separate chunk (about.[hash].js) for this route
</span><span style="color:#75715e"></span>      <span style="color:#75715e">// which is lazy-loaded when the route is visited.
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">About</span>
    }
  ]
})
 
</code></pre></div><p>那么 这些路由组件怎么展示呢？在哪里展示呢？
这里我们要看到 App.vue 文件</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html"> 
&lt;<span style="color:#f92672">template</span>&gt;
  &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">id</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;app&#34;</span>&gt;
    &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">id</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;nav&#34;</span>&gt;
      &lt;<span style="color:#f92672">router-link</span> <span style="color:#a6e22e">to</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;/&#34;</span>&gt;Home&lt;/<span style="color:#f92672">router-link</span>&gt; 
       <span style="color:#75715e">&lt;!-- 使用router-link标签 添加 to属性决定我们要路由到什么地方 --&gt;</span>
      &lt;<span style="color:#f92672">router-link</span> <span style="color:#a6e22e">to</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;/about&#34;</span>&gt;About&lt;/<span style="color:#f92672">router-link</span>&gt;
      
    &lt;/<span style="color:#f92672">div</span>&gt;
    &lt;<span style="color:#f92672">router-view</span>/&gt;    
    <span style="color:#75715e">&lt;!-- router-view 就是我们要展示路由的地方  --&gt;</span>
  &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
 
&lt;<span style="color:#f92672">style</span>&gt;
#app {
  <span style="color:#66d9ef">font-family</span>: <span style="color:#e6db74">&#39;Avenir&#39;</span>, Helvetica, Arial, <span style="color:#66d9ef">sans-serif</span>;
  <span style="color:#66d9ef">-webkit-</span>font-smoothing: antialiased;
  <span style="color:#66d9ef">-moz-</span>osx-font-smoothing: grayscale;
  <span style="color:#66d9ef">text-align</span>: <span style="color:#66d9ef">center</span>;
  <span style="color:#66d9ef">color</span>: <span style="color:#ae81ff">#2c3e50</span>;
}
#nav {
  <span style="color:#66d9ef">padding</span>: <span style="color:#ae81ff">30</span><span style="color:#66d9ef">px</span>;
}
 
#nav <span style="color:#f92672">a</span> {
  <span style="color:#66d9ef">font-weight</span>: <span style="color:#66d9ef">bold</span>;
  <span style="color:#66d9ef">color</span>: <span style="color:#ae81ff">#2c3e50</span>;
}
 
#nav <span style="color:#f92672">a</span>.<span style="color:#a6e22e">router-link-exact-active</span> {
  <span style="color:#66d9ef">color</span>: <span style="color:#ae81ff">#42b983</span>;
}
&lt;/<span style="color:#f92672">style</span>&gt;
</code></pre></div><p>到这里 我们一个简单的基础的路由已经写好了 可以使用了</p>
<h2 id="vue-router-的子路由">vue-router 的子路由</h2>
<p>如何创建子路由呢？其实也是相当简单的</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">//router.js
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Router</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue-router&#39;</span>  <span style="color:#75715e">//这里引用了vue-router 并且用Vue.use来使用Router
</span><span style="color:#75715e"></span>
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Router</span>)
 
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">Home</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/Home.vue&#39;</span>)   <span style="color:#75715e">//使用常量模式 提前声明 并且在component中使用 这样我们就完成了一个可以简单实用的路由了
</span><span style="color:#75715e"></span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">About</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/About.vue&#39;</span>)
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">Children</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/Children.vue&#39;</span>)  <span style="color:#75715e">//我们引入这个页面 页面内容
</span><span style="color:#75715e"></span>
<span style="color:#75715e">// Router的内置属性
</span><span style="color:#75715e"></span><span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Router</span>({
  <span style="color:#75715e">// mode: &#39;history&#39;,  
</span><span style="color:#75715e"></span>  <span style="color:#a6e22e">base</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">process</span>.<span style="color:#a6e22e">env</span>.<span style="color:#a6e22e">BASE_URL</span>,  
  <span style="color:#a6e22e">routes</span><span style="color:#f92672">:</span> [
    {
      <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/&#39;</span>,       
      <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;home&#39;</span>,
      <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">Home</span>,
      <span style="color:#a6e22e">children</span><span style="color:#f92672">:</span>[
        {
          <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;about&#39;</span>,  
          <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;about&#39;</span>,
          <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">About</span>,
        },
        {
          <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;children&#39;</span>,
          <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;children&#39;</span>,
          <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span><span style="color:#a6e22e">Children</span>
        },  <span style="color:#75715e">//这时候我们访问 访问about 实际上是home的子路由了
</span><span style="color:#75715e"></span>        <span style="color:#75715e">// 它是home的子路由，所以我們需要在home里面再书写一个路由显示的组件  &lt;router-view/&gt;   子路由的内容就会显示在其 router-view下面
</span><span style="color:#75715e"></span>      ]
    }
  ]
})
 
</code></pre></div><p>这里我把改进后的 app.vue 和 about.vue 等代码贴出。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html"><span style="color:#75715e">&lt;!-- app --&gt;</span>
&lt;<span style="color:#f92672">template</span>&gt;
  &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">id</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;app&#34;</span>&gt;
    &lt;<span style="color:#f92672">router-view</span>/&gt;
  &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
 
&lt;<span style="color:#f92672">style</span>&gt;
#app {
  <span style="color:#66d9ef">font-family</span>: <span style="color:#e6db74">&#39;Avenir&#39;</span>, Helvetica, Arial, <span style="color:#66d9ef">sans-serif</span>;
  <span style="color:#66d9ef">-webkit-</span>font-smoothing: antialiased;
  <span style="color:#66d9ef">-moz-</span>osx-font-smoothing: grayscale;
  <span style="color:#66d9ef">text-align</span>: <span style="color:#66d9ef">center</span>;
  <span style="color:#66d9ef">color</span>: <span style="color:#ae81ff">#2c3e50</span>;
}
#nav {
  <span style="color:#66d9ef">padding</span>: <span style="color:#ae81ff">30</span><span style="color:#66d9ef">px</span>;
}
 
#nav <span style="color:#f92672">a</span> {
  <span style="color:#66d9ef">font-weight</span>: <span style="color:#66d9ef">bold</span>;
  <span style="color:#66d9ef">color</span>: <span style="color:#ae81ff">#2c3e50</span>;
}
 
#nav <span style="color:#f92672">a</span>.<span style="color:#a6e22e">router-link-exact-active</span> {
  <span style="color:#66d9ef">color</span>: <span style="color:#ae81ff">#42b983</span>;
}
&lt;/<span style="color:#f92672">style</span>&gt;
 
<span style="color:#75715e">&lt;!-- about --&gt;</span>
&lt;<span style="color:#f92672">template</span>&gt;
  &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;about&#34;</span>&gt;
    &lt;<span style="color:#f92672">h1</span>&gt;This is an about page&lt;/<span style="color:#f92672">h1</span>&gt;
  &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
 
&lt;<span style="color:#f92672">template</span>&gt;
<span style="color:#75715e">&lt;!-- children --&gt;</span>
  &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;children&#34;</span>&gt;
    &lt;<span style="color:#f92672">h1</span>&gt;This is an children page&lt;/<span style="color:#f92672">h1</span>&gt;
  &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
<span style="color:#75715e">&lt;!-- home --&gt;</span>
&lt;<span style="color:#f92672">template</span>&gt;
  &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;home&#34;</span>&gt;
    &lt;<span style="color:#f92672">img</span> <span style="color:#a6e22e">alt</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Vue logo&#34;</span> <span style="color:#a6e22e">src</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;../assets/logo.png&#34;</span>&gt;
    &lt;<span style="color:#f92672">div</span>&gt;
      <span style="color:#75715e">&lt;!-- &lt;router-link to=&#34;/&#34;&gt;Home&lt;/router-link&gt; | --&gt;</span>
      &lt;<span style="color:#f92672">router-link</span> <span style="color:#a6e22e">to</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;/about&#34;</span>&gt;About&lt;/<span style="color:#f92672">router-link</span>&gt; |
      &lt;<span style="color:#f92672">router-link</span> <span style="color:#a6e22e">to</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;/children&#34;</span>&gt;children&lt;/<span style="color:#f92672">router-link</span>&gt;
    &lt;/<span style="color:#f92672">div</span>&gt;
 
      &lt;<span style="color:#f92672">router-view</span>&gt;&lt;/<span style="color:#f92672">router-view</span>&gt;
  &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
 
&lt;<span style="color:#f92672">script</span>&gt;
<span style="color:#75715e">// @ is an alias to /src
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">HelloWorld</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;@/components/HelloWorld.vue&#39;</span>
 
<span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> {
  <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;home&#39;</span>,
  <span style="color:#a6e22e">components</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">HelloWorld</span>
  }
}
&lt;/<span style="color:#f92672">script</span>&gt;
 
</code></pre></div><h2 id="vue-router-传参">vue-router 传参</h2>
<p><strong>编程式的导航 router.push</strong>
编程式的导航传参我们需要使用 this.$router.push() 这个方法 我们有三种传参方式</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html">&lt;<span style="color:#f92672">script</span>&gt;
<span style="color:#75715e">// 字符串
</span><span style="color:#75715e"></span>
<span style="color:#75715e">// 这种方式可以实现路由跳转 但是没有办法获取到参数 没有办法传参
</span><span style="color:#75715e"></span><span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$router</span>.<span style="color:#a6e22e">push</span>(<span style="color:#e6db74">&#34;children&#34;</span>);
<span style="color:#75715e">// 对象传参
</span><span style="color:#75715e">// 特别注意：命名路由这种方式传递的参数，如果在目标页面刷新是会出错的
</span><span style="color:#75715e">// 如果想要在刷新后还可以获取到参数就要用到我们讲的动态路由 例如： /children/:userId 这时候 如果使用了这种模式 目标地址栏会变为 /children/qm
</span><span style="color:#75715e"></span><span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$router</span>.<span style="color:#a6e22e">push</span>({ <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;children&#39;</span>, <span style="color:#a6e22e">params</span><span style="color:#f92672">:</span> { <span style="color:#a6e22e">userId</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;qm&#39;</span> }})
 
<span style="color:#75715e">// 想要传递参数主要就是以对象的方式来写，分为两种方式：命名路由、查询参数，下面分别说明两种方式的用法和注意事项。
</span><span style="color:#75715e"></span>
<span style="color:#75715e">// 查询参数
</span><span style="color:#75715e"></span><span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$router</span>.<span style="color:#a6e22e">push</span>({ <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/children&#39;</span>, <span style="color:#a6e22e">query</span><span style="color:#f92672">:</span> { <span style="color:#a6e22e">userId</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;qm&#39;</span> }});
<span style="color:#75715e">// 这种方式参数是暴露在地址栏上面的
</span><span style="color:#75715e"></span>&lt;/<span style="color:#f92672">script</span>&gt;
 
 
</code></pre></div><p><strong>声明式的导航</strong>
声明式的导航也分为三种方式</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html"><span style="color:#75715e">&lt;!-- 字符串 --&gt;</span>
  &lt;<span style="color:#f92672">router-link</span> <span style="color:#a6e22e">to</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;children&#34;</span>&gt;click to news page&lt;/<span style="color:#f92672">router-link</span>&gt;
<span style="color:#75715e">&lt;!-- 命名路由 --&gt;</span>
  &lt;<span style="color:#f92672">router-link</span> <span style="color:#a6e22e">:to</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;{ name: &#39;children&#39;, params: { userId: &#39;qm&#39;}}&#34;</span>&gt;click to news page&lt;/<span style="color:#f92672">router-link</span>&gt;
<span style="color:#75715e">&lt;!-- 查询参数 --&gt;</span>
  &lt;<span style="color:#f92672">router-link</span> <span style="color:#a6e22e">:to</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;{ path: &#39;/children&#39;, query: { userId: &#39;qm&#39;}}&#34;</span>&gt;click to news page&lt;/<span style="color:#f92672">router-link</span>&gt;
</code></pre></div><p>接受参数使用 this.$router 后面就是搭配路由的名称就能获取到参数的值</p>
<p><strong>url 传参</strong></p>
<p>这种传参方法我们需要在书写路由的时候做一个小小的改动</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"> 
<span style="color:#75715e">//router.js
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Router</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue-router&#39;</span>
 
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Router</span>)
 
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">Home</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/Home.vue&#39;</span>)   
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">About</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/About.vue&#39;</span>)
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">Children</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/Children.vue&#39;</span>)
 
<span style="color:#75715e">// Router的内置属性
</span><span style="color:#75715e"></span><span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Router</span>({
  <span style="color:#75715e">// mode: &#39;history&#39;,  
</span><span style="color:#75715e"></span>  <span style="color:#a6e22e">base</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">process</span>.<span style="color:#a6e22e">env</span>.<span style="color:#a6e22e">BASE_URL</span>,  
  <span style="color:#a6e22e">routes</span><span style="color:#f92672">:</span> [
    {
      <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/&#39;</span>,       
      <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;home&#39;</span>,
      <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">Home</span>,
      <span style="color:#a6e22e">children</span><span style="color:#f92672">:</span>[
        {
          <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;about/:id&#39;</span>,  <span style="color:#75715e">// 我们在后面加入/:id 这样我们在url输入的地址相应就变成了 /about/3  我们在about组件内 通过 this.$route.params  如何动态监听路由的变化呢？要知道当我们仅仅参数变化组件可是没有刷新的，提示一下 watch可是可以监听某些数据哦~实战课程我会带大家了解一下这个该如何运用
</span><span style="color:#75715e"></span>          <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;about&#39;</span>,
          <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">About</span>,
        },
        {
          <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;children&#39;</span>,
          <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;children&#39;</span>,
          <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span><span style="color:#a6e22e">Children</span>
        }, 
      ]
    }
  ]
})
 
</code></pre></div><p>相应页面改动如下 home.vue about.vue</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html"><span style="color:#75715e">&lt;!-- about --&gt;</span>
&lt;<span style="color:#f92672">template</span>&gt;
  &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;about&#34;</span>&gt;
    &lt;<span style="color:#f92672">h1</span>&gt;This is an about page&lt;/<span style="color:#f92672">h1</span>&gt;
    {{this.$route.params.id}}
  &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
 
<span style="color:#75715e">&lt;!-- home --&gt;</span>
&lt;<span style="color:#f92672">template</span>&gt;
  &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;home&#34;</span>&gt;
    &lt;<span style="color:#f92672">img</span> <span style="color:#a6e22e">alt</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Vue logo&#34;</span> <span style="color:#a6e22e">src</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;../assets/logo.png&#34;</span>&gt;
    &lt;<span style="color:#f92672">div</span>&gt;
      &lt;<span style="color:#f92672">router-link</span> <span style="color:#a6e22e">to</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;/about/3&#34;</span>&gt;About&lt;/<span style="color:#f92672">router-link</span>&gt; |   
      &lt;<span style="color:#f92672">router-link</span> <span style="color:#a6e22e">to</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;/children&#34;</span>&gt;children&lt;/<span style="color:#f92672">router-link</span>&gt;
    &lt;/<span style="color:#f92672">div</span>&gt;
 
      &lt;<span style="color:#f92672">router-view</span>&gt;&lt;/<span style="color:#f92672">router-view</span>&gt;
  &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
 
&lt;<span style="color:#f92672">script</span>&gt;
<span style="color:#75715e">// @ is an alias to /src
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">HelloWorld</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;@/components/HelloWorld.vue&#39;</span>
 
<span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> {
  <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;home&#39;</span>,
  <span style="color:#a6e22e">components</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">HelloWorld</span>
  },
}
&lt;/<span style="color:#f92672">script</span>&gt;
 
</code></pre></div><p><strong>404 的制作</strong></p>
<p>其实 vue-router 里面还有很多细节内容，这里由于我们是基础课程所以不做太详细的介绍，相信大家在浏览网页的时候经常会看到 404 页面，那么用我们的 vue-router 如何去实现一个 404 呢？实际上是非常简单的
我们需要在 router.js 里面书写一个通配路径放置在最后位置，当所有的路径都不匹配的时候，就会去通配这样一个 404 页面提示大家页面丢失了，下面我详细给大家书写一下</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">// router.js
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Router</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue-router&#39;</span>
 
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Router</span>)
 
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">Home</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/Home.vue&#39;</span>)   
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">About</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/About.vue&#39;</span>)
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">Children</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/Children.vue&#39;</span>)
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">NotFound</span> <span style="color:#f92672">=</span> ()=&gt; <span style="color:#66d9ef">import</span>(<span style="color:#e6db74">&#39;./views/notFound.vue&#39;</span>)
 
<span style="color:#75715e">// Router的内置属性
</span><span style="color:#75715e"></span><span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Router</span>({
  <span style="color:#75715e">// mode: &#39;history&#39;,  
</span><span style="color:#75715e"></span>  <span style="color:#a6e22e">base</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">process</span>.<span style="color:#a6e22e">env</span>.<span style="color:#a6e22e">BASE_URL</span>,  
  <span style="color:#a6e22e">routes</span><span style="color:#f92672">:</span> [
    {
      <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/&#39;</span>,       
      <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;home&#39;</span>,
      <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">Home</span>,
      <span style="color:#a6e22e">children</span><span style="color:#f92672">:</span>[
        {
          <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;about/:id&#39;</span>, 
          <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;about&#39;</span>,
          <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">About</span>,
        },
        {
          <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;children&#39;</span>,
          <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;children&#39;</span>,
          <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span><span style="color:#a6e22e">Children</span>
        },
      ]
    },
    {
      <span style="color:#a6e22e">path</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;*&#39;</span>,
      <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;404&#39;</span>,
      <span style="color:#a6e22e">component</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">NotFound</span>,
    }
  ]
})
 
</code></pre></div><p>学完这些，你对于 vue-router 的基本运用已经可以算是合格了，工作中的大部分用法也都接触到了，我们接下来讲解 vuex。</p>
<h2 id="vuex">vuex</h2>
<p>首先来一个小 demo 展示一下 vuex 的具体用途</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">// store.js
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vuex</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vuex&#39;</span>
 
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Vuex</span>)
 
<span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Vuex</span>.<span style="color:#a6e22e">Store</span>({
  <span style="color:#a6e22e">state</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">number</span><span style="color:#f92672">:</span><span style="color:#ae81ff">0</span>,
  },
  <span style="color:#a6e22e">mutations</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">ADD</span>(<span style="color:#a6e22e">state</span>){
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">++</span>
    },
    <span style="color:#a6e22e">SUB</span>(<span style="color:#a6e22e">state</span>){
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">--</span>
    }
  },
  <span style="color:#a6e22e">actions</span><span style="color:#f92672">:</span> {
 
  }
})
<span style="color:#75715e">&lt;!--</span> <span style="color:#a6e22e">children</span>.<span style="color:#a6e22e">vue</span> <span style="color:#f92672">--&gt;</span>
<span style="color:#f92672">&lt;</span><span style="color:#a6e22e">template</span><span style="color:#f92672">&gt;</span>
  <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">div</span> <span style="color:#66d9ef">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;children&#34;</span><span style="color:#f92672">&gt;</span>
    <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">h1</span><span style="color:#f92672">&gt;</span><span style="color:#a6e22e">This</span> <span style="color:#a6e22e">is</span> <span style="color:#a6e22e">an</span> <span style="color:#a6e22e">children</span> <span style="color:#a6e22e">page</span><span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/h1&gt;</span>
    <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">button</span> <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;add&#34;</span><span style="color:#f92672">&gt;</span>
      <span style="color:#f92672">+</span>
    <span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/button&gt;</span>
      {{<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span>}}
      <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">button</span>  <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;sub&#34;</span><span style="color:#f92672">&gt;</span>
      <span style="color:#f92672">-</span>
    <span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/button&gt;</span>
  <span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/div&gt;</span>
<span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/template&gt;</span>
 
<span style="color:#f92672">&lt;</span><span style="color:#a6e22e">script</span><span style="color:#f92672">&gt;</span>
  <span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span>{
    <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;children&#39;</span>,
    <span style="color:#a6e22e">methods</span><span style="color:#f92672">:</span> {
      <span style="color:#a6e22e">add</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;ADD&#39;</span>)
      },
      <span style="color:#a6e22e">sub</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;SUB&#39;</span>)
      }
    }
  }
<span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/script&gt;</span>
</code></pre></div><p>这样一个小小的 demo 实际上已经诠释了我们 vuex 的作用，我们需要在刷新之前永久保留的状态，并且想要远距离传参并且及时做出响应，那么都可以使用 vuex 来进行。它就是一个状态管理和加工的仓库，一共有五个重要属性，state，mutations，actions , getter , module 这么五个小玩意 我会带大家一个一个认识他们的作用，并且教会大家基本用法，当然了，它也是有较为高级的小用法的。我们实战课也会使用稍微高级的用法来讲解。</p>
<h2 id="state-属性">state 属性</h2>
<p>我们用 VUE 文件来类比讲解 store
state 就相当于 vue 中的 data 属性，所有的状态或者说是数据都存储在这个 state 里面，我们在别的地方获取需要使用 this.$store.state.属性名称 来获取相应的值，并且我们可以通过 mutations 和 actions 来改变 state 的值，从而触发所有使用到 state 的地方刷新。state 里可以存储各种数据类型，data 里面可以用的数据类型，state 里面同样可以使用。</p>
<h2 id="getters-属性">getters 属性</h2>
<p>getters 我们类比到 vue 中，那么它应该是 computed 了 我们在使用的时候 要使用 this.$store.getters.属性名 用法也和 computed 类似，它实际上是调用一个方法，然后获取到的数据是经过一系列处理后并且 return 回来的数据，它的具体写法是。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">// store.js
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vuex</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vuex&#39;</span>
 
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Vuex</span>)
 
<span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Vuex</span>.<span style="color:#a6e22e">Store</span>({
  <span style="color:#a6e22e">state</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">number</span><span style="color:#f92672">:</span><span style="color:#ae81ff">0</span>,
  },
  <span style="color:#a6e22e">mutations</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">ADD</span>(<span style="color:#a6e22e">state</span>){
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">++</span>
    },
    <span style="color:#a6e22e">SUB</span>(<span style="color:#a6e22e">state</span>){
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">--</span>
    }
  },
  <span style="color:#a6e22e">actions</span><span style="color:#f92672">:</span> {
 
  },
  <span style="color:#a6e22e">getters</span><span style="color:#f92672">:</span>{
    <span style="color:#a6e22e">getNumber</span>(<span style="color:#a6e22e">state</span>){   <span style="color:#75715e">//getter的书写方法
</span><span style="color:#75715e"></span>      <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span> <span style="color:#f92672">+</span> <span style="color:#ae81ff">100</span>
    }
  }
})
<span style="color:#75715e">&lt;!--</span> <span style="color:#a6e22e">children</span>.<span style="color:#a6e22e">vue</span> <span style="color:#f92672">--&gt;</span>
<span style="color:#f92672">&lt;</span><span style="color:#a6e22e">template</span><span style="color:#f92672">&gt;</span>
  <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">div</span> <span style="color:#66d9ef">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;children&#34;</span><span style="color:#f92672">&gt;</span>
    <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">h1</span><span style="color:#f92672">&gt;</span><span style="color:#a6e22e">This</span> <span style="color:#a6e22e">is</span> <span style="color:#a6e22e">an</span> <span style="color:#a6e22e">children</span> <span style="color:#a6e22e">page</span><span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/h1&gt;</span>
    <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">button</span> <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;add&#34;</span><span style="color:#f92672">&gt;</span>
      <span style="color:#f92672">+</span>
    <span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/button&gt;</span>
      {{<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span>}}
      {{<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">getters</span>.<span style="color:#a6e22e">getNumber</span>}}
      <span style="color:#75715e">&lt;!--</span> <span style="color:#a6e22e">getters的基础调用方法</span><span style="color:#960050;background-color:#1e0010">，</span><span style="color:#a6e22e">当然还有更高级的</span> <span style="color:#a6e22e">实战课会讲解</span> <span style="color:#f92672">--&gt;</span>
      <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">button</span>  <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;sub&#34;</span><span style="color:#f92672">&gt;</span>
      <span style="color:#f92672">-</span>
    <span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/button&gt;</span>
  <span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/div&gt;</span>
<span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/template&gt;</span>
 
<span style="color:#f92672">&lt;</span><span style="color:#a6e22e">script</span><span style="color:#f92672">&gt;</span>
  <span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span>{
    <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;children&#39;</span>,
    <span style="color:#a6e22e">methods</span><span style="color:#f92672">:</span> {
      <span style="color:#a6e22e">add</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;ADD&#39;</span>)
      },
      <span style="color:#a6e22e">sub</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;SUB&#39;</span>)
      }
    }
  }
<span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/script&gt;</span>
</code></pre></div><p>这就是 getters 的简单实用</p>
<h2 id="mutations">mutations</h2>
<p>mutations 类比到 vuex 中应该是 methods
它是更改 Vuex 的 store 中的状态的唯一方法是提交 mutation。Vuex 中的 mutation 非常类似于事件：每个 mutation 都有一个字符串的 事件类型 (type) 和 一个 回调函数 (handler)。这个回调函数就是我们实际进行状态更改的地方，并且它会接受 state 作为第一个参数：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">// store.js
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vuex</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vuex&#39;</span>
 
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Vuex</span>)
 
<span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Vuex</span>.<span style="color:#a6e22e">Store</span>({
  <span style="color:#a6e22e">state</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">number</span><span style="color:#f92672">:</span><span style="color:#ae81ff">0</span>,
  },
  <span style="color:#a6e22e">mutations</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">ADD</span>(<span style="color:#a6e22e">state</span>){  <span style="color:#75715e">//我们把state传入 就可以对 state内的数据进行我们想要的变化，它必须按照我们想要得到的格式去变化， 想要直接提交mutations 需要使用 this.$stote.commit(&#39;mutations的方法名&#39;,参数) 如果想要在mutations方法中传参，写法就要变成 ADD(state,形参){ ... } 这样一种形式了 我举个例子
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">++</span>
    },
    <span style="color:#a6e22e">SUB</span>(<span style="color:#a6e22e">state</span>){
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">--</span>
    },
    <span style="color:#75715e">// ADDPARAM(state,param){
</span><span style="color:#75715e"></span>    <span style="color:#75715e">//   if (typeof param !== &#39;number&#39;){
</span><span style="color:#75715e"></span>    <span style="color:#75715e">//     param = 0
</span><span style="color:#75715e"></span>    <span style="color:#75715e">//   }
</span><span style="color:#75715e"></span>    <span style="color:#75715e">//   state.number = state.number + param
</span><span style="color:#75715e"></span>    <span style="color:#75715e">// }  这个方法就可以传入我们想用的参数了，相应调用的地方也需要改变
</span><span style="color:#75715e"></span>  },
  <span style="color:#a6e22e">actions</span><span style="color:#f92672">:</span> {
 
  },
  <span style="color:#a6e22e">getters</span><span style="color:#f92672">:</span>{
    <span style="color:#a6e22e">getNumber</span>(<span style="color:#a6e22e">state</span>){   <span style="color:#75715e">//getter的书写方法
</span><span style="color:#75715e"></span>      <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span> <span style="color:#f92672">+</span> <span style="color:#ae81ff">100</span>
    }
  }
})
</code></pre></div><p>带参数的 commit 如何使用</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html"><span style="color:#75715e">&lt;!-- children.vue --&gt;</span>
&lt;<span style="color:#f92672">template</span>&gt;
  &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;children&#34;</span>&gt;
    &lt;<span style="color:#f92672">h1</span>&gt;This is an children page&lt;/<span style="color:#f92672">h1</span>&gt;
    &lt;<span style="color:#f92672">button</span> <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;add&#34;</span>&gt;
      +
    &lt;/<span style="color:#f92672">button</span>&gt;
      {{$store.state.number}}
      {{$store.getters.getNumber}}
      <span style="color:#75715e">&lt;!-- getters的基础调用方法，当然还有更高级的 实战课会讲解 --&gt;</span>
      &lt;<span style="color:#f92672">button</span>  <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;sub&#34;</span>&gt;
      -
    &lt;/<span style="color:#f92672">button</span>&gt;
  &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
 
&lt;<span style="color:#f92672">script</span>&gt;
  <span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span>{
    <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;children&#39;</span>,
    <span style="color:#a6e22e">methods</span><span style="color:#f92672">:</span> {
      <span style="color:#a6e22e">add</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;ADD&#39;</span>)
      },
      <span style="color:#75715e">// addparam() {
</span><span style="color:#75715e"></span>      <span style="color:#75715e">//   this.$store.commit(&#39;ADDPARAM&#39;,5)
</span><span style="color:#75715e"></span>      <span style="color:#75715e">// }, 
</span><span style="color:#75715e"></span>      <span style="color:#75715e">//  this.$store.commit(&#39;要提交的mutations名字&#39;,要传入的参数)
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">sub</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;SUB&#39;</span>)
      }
    }
  }
&lt;/<span style="color:#f92672">script</span>&gt;
 
</code></pre></div><h2 id="actions-属性">actions 属性</h2>
<p>actions 属性用法和 mutations 类似，但是 actions 我们是不可以修改 state 的 需要在 actions 通过 commit 来调用 mutations 来修改数据，那么 action 的意义何在呢？处理异步事件就要用 action 来做了呀。调用方法是，this.$store.dispatch(&ldquo;action 的名字&rdquo;，参数)</p>
<p>书写的方法呢 我给大家展示一下</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">// store.js
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vuex</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vuex&#39;</span>
 
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Vuex</span>)
 
<span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Vuex</span>.<span style="color:#a6e22e">Store</span>({
  <span style="color:#a6e22e">state</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">number</span><span style="color:#f92672">:</span><span style="color:#ae81ff">0</span>,
  },
  <span style="color:#a6e22e">mutations</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">ADD</span>(<span style="color:#a6e22e">state</span>){ 
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">++</span>
    },
    <span style="color:#a6e22e">SUB</span>(<span style="color:#a6e22e">state</span>){
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">--</span>
    },
    <span style="color:#a6e22e">ADDPARAM</span>(<span style="color:#a6e22e">state</span>,<span style="color:#a6e22e">param</span>){
      <span style="color:#66d9ef">if</span> (<span style="color:#66d9ef">typeof</span> <span style="color:#a6e22e">param</span> <span style="color:#f92672">!==</span> <span style="color:#e6db74">&#39;number&#39;</span>){
        <span style="color:#a6e22e">param</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
      }
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">param</span>
    } 
  },
  <span style="color:#a6e22e">actions</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">ASYNCADD</span>(<span style="color:#a6e22e">context</span>,<span style="color:#a6e22e">param</span>){  <span style="color:#75715e">//这里我们传入context上下文，里面包含 commit, state ,getters 这三个属性都可以通过context来调用到并且触发内部方法
</span><span style="color:#75715e"></span>      <span style="color:#a6e22e">setTimeout</span>(<span style="color:#66d9ef">function</span>(){
        <span style="color:#a6e22e">context</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;ADDPARAM&#39;</span>,<span style="color:#a6e22e">param</span>)
      },<span style="color:#ae81ff">1000</span>)
    }
  },
  <span style="color:#a6e22e">getters</span><span style="color:#f92672">:</span>{
    <span style="color:#a6e22e">getNumber</span>(<span style="color:#a6e22e">state</span>){   <span style="color:#75715e">//getter的书写方法
</span><span style="color:#75715e"></span>      <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span> <span style="color:#f92672">+</span> <span style="color:#ae81ff">100</span>
    }
  }
})
</code></pre></div><p>action 的使用</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html"><span style="color:#75715e">&lt;!-- children.vue --&gt;</span>
&lt;<span style="color:#f92672">template</span>&gt;
  &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;children&#34;</span>&gt;
    &lt;<span style="color:#f92672">h1</span>&gt;This is an children page&lt;/<span style="color:#f92672">h1</span>&gt;
    &lt;<span style="color:#f92672">button</span> <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;add&#34;</span>&gt;
      +
    &lt;/<span style="color:#f92672">button</span>&gt;
      {{$store.state.number}}
      {{$store.getters.getNumber}}
      &lt;<span style="color:#f92672">button</span>  <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;sub&#34;</span>&gt;
      -
    &lt;/<span style="color:#f92672">button</span>&gt;
    
 
    &lt;<span style="color:#f92672">button</span> <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;actAdd&#34;</span>&gt;action&lt;/<span style="color:#f92672">button</span>&gt;
  &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
 
&lt;<span style="color:#f92672">script</span>&gt;
  <span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span>{
    <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;children&#39;</span>,
    <span style="color:#a6e22e">methods</span><span style="color:#f92672">:</span> {
      <span style="color:#a6e22e">add</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;ADD&#39;</span>)
      },
      <span style="color:#a6e22e">actAdd</span>(){   <span style="color:#75715e">// 我们通过 dispatch来调用action 然后由action去提交我们的 mutations来达到异步更改状态的目的
</span><span style="color:#75715e"></span>        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">dispatch</span>(<span style="color:#e6db74">&#39;ASYNCADD&#39;</span>,<span style="color:#ae81ff">50</span>)
      },
      <span style="color:#a6e22e">sub</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;SUB&#39;</span>)
      }
    }
  }
&lt;/<span style="color:#f92672">script</span>&gt;
 
</code></pre></div><p>vuex 是不是非常简单呢，到这里大家可能在想，如果我的项目很大 我有很多的这些个方法啊，状态啊，我都写在这里不就乱了吗？没错，肯定乱了，所以 vuex 还提供了 modules 方便我们分块管理</p>
<h2 id="modules">modules</h2>
<p>由于使用单一状态树，应用的所有状态会集中到一个比较大的对象。当应用变得非常复杂时，store 对象就有可能变得相当臃肿。
为了解决以上问题，Vuex 允许我们将 store 分割成模块（module）。每个模块拥有自己的 state、mutation、action、getter、甚至是嵌套子模块——从上至下进行同样方式的分割</p>
<p>我们把上面的这些个代码分割出去</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">// store.js
</span><span style="color:#75715e"></span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vue</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vue&#39;</span>
<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">Vuex</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;vuex&#39;</span>
 
<span style="color:#a6e22e">Vue</span>.<span style="color:#a6e22e">use</span>(<span style="color:#a6e22e">Vuex</span>)
 
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">children</span> <span style="color:#f92672">=</span> {   <span style="color:#75715e">// 因为我们是写在了children这个组件里面 这个命名规则也好让我们知道它存在于哪里
</span><span style="color:#75715e"></span>  <span style="color:#a6e22e">state</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">number</span><span style="color:#f92672">:</span><span style="color:#ae81ff">0</span>,
  },
  <span style="color:#a6e22e">mutations</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">ADD</span>(<span style="color:#a6e22e">state</span>){  
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">++</span>
    },
    <span style="color:#a6e22e">SUB</span>(<span style="color:#a6e22e">state</span>){
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span><span style="color:#f92672">--</span>
    },
    <span style="color:#a6e22e">ADDPARAM</span>(<span style="color:#a6e22e">state</span>,<span style="color:#a6e22e">param</span>){
      <span style="color:#66d9ef">if</span> (<span style="color:#66d9ef">typeof</span> <span style="color:#a6e22e">param</span> <span style="color:#f92672">!==</span> <span style="color:#e6db74">&#39;number&#39;</span>){
        <span style="color:#a6e22e">param</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
      }
      <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">param</span>
    }  
  },
  <span style="color:#a6e22e">actions</span><span style="color:#f92672">:</span> {
    <span style="color:#a6e22e">ASYNCADD</span>(<span style="color:#a6e22e">context</span>,<span style="color:#a6e22e">param</span>){  
      <span style="color:#a6e22e">setTimeout</span>(<span style="color:#66d9ef">function</span>(){
        <span style="color:#a6e22e">context</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;ADDPARAM&#39;</span>,<span style="color:#a6e22e">param</span>)
      },<span style="color:#ae81ff">1000</span>)
    }
  },
  <span style="color:#a6e22e">getters</span><span style="color:#f92672">:</span>{
    <span style="color:#a6e22e">getNumber</span>(<span style="color:#a6e22e">state</span>){   
      <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">number</span> <span style="color:#f92672">+</span> <span style="color:#ae81ff">100</span>
    }
  }
}
 
 
<span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">Vuex</span>.<span style="color:#a6e22e">Store</span>({
  <span style="color:#a6e22e">modules</span><span style="color:#f92672">:</span>{
    <span style="color:#a6e22e">children</span>, <span style="color:#75715e">// 这里我们把children传入以后 还是一样可以使用我们的哪些方法，不过我们是state要加上 modules名字 所以我们的children.vue 要相应修改
</span><span style="color:#75715e"></span>  }
})
<span style="color:#75715e">&lt;!--</span> <span style="color:#a6e22e">children</span>.<span style="color:#a6e22e">vue</span> <span style="color:#f92672">--&gt;</span>
<span style="color:#f92672">&lt;</span><span style="color:#a6e22e">template</span><span style="color:#f92672">&gt;</span>
  <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">div</span> <span style="color:#66d9ef">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;children&#34;</span><span style="color:#f92672">&gt;</span>
    <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">h1</span><span style="color:#f92672">&gt;</span><span style="color:#a6e22e">This</span> <span style="color:#a6e22e">is</span> <span style="color:#a6e22e">an</span> <span style="color:#a6e22e">children</span> <span style="color:#a6e22e">page</span><span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/h1&gt;</span>
    <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">button</span> <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;add&#34;</span><span style="color:#f92672">&gt;</span>
      <span style="color:#f92672">+</span>
    <span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/button&gt;</span>
      {{<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">children</span>.<span style="color:#a6e22e">number</span>}}
      <span style="color:#75715e">&lt;!--</span> <span style="color:#a6e22e">大家可以看到</span><span style="color:#960050;background-color:#1e0010">，</span><span style="color:#a6e22e">这里需要加上modules名字才可以获取到number</span> <span style="color:#a6e22e">但是其余的不需要处理</span><span style="color:#960050;background-color:#1e0010">，</span><span style="color:#a6e22e">所以我们开发中一般想要获取到</span> <span style="color:#a6e22e">state</span> <span style="color:#a6e22e">最好是通过getter来获取</span>  <span style="color:#f92672">--&gt;</span>
      {{<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">getters</span>.<span style="color:#a6e22e">getNumber</span>}}
      <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">button</span>  <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;sub&#34;</span><span style="color:#f92672">&gt;</span>
      <span style="color:#f92672">-</span>
    <span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/button&gt;</span>
    
 
    <span style="color:#f92672">&lt;</span><span style="color:#a6e22e">button</span> <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">click</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;actAdd&#34;</span><span style="color:#f92672">&gt;</span><span style="color:#a6e22e">action</span><span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/button&gt;</span>
  <span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/div&gt;</span>
<span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/template&gt;</span>
 
<span style="color:#f92672">&lt;</span><span style="color:#a6e22e">script</span><span style="color:#f92672">&gt;</span>
  <span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span>{
    <span style="color:#a6e22e">name</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;children&#39;</span>,
    <span style="color:#a6e22e">methods</span><span style="color:#f92672">:</span> {
      <span style="color:#a6e22e">add</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;ADD&#39;</span>)
      },
      <span style="color:#a6e22e">actAdd</span>(){   <span style="color:#75715e">// 我们通过 dispatch来调用action 然后由action去提交我们的 mutations来达到异步更改状态的目的
</span><span style="color:#75715e"></span>        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">dispatch</span>(<span style="color:#e6db74">&#39;ASYNCADD&#39;</span>,<span style="color:#ae81ff">50</span>)
      },
      <span style="color:#a6e22e">sub</span>() {
        <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$store</span>.<span style="color:#a6e22e">commit</span>(<span style="color:#e6db74">&#39;SUB&#39;</span>)
      }
    },
  }
<span style="color:#f92672">&lt;</span><span style="color:#960050;background-color:#1e0010">/script&gt;</span>
 
</code></pre></div><p>很多时候，我们在正式使用中都会加上命名空间，也就是 modules 里面的 namespaced 属性我们让它变为 namespaced: true, 如果大家想要学习，可以去 vuex 文档学习，得益于 es6 vuex 给我们提供了
mapState, mapGetters, mapActions 和 mapMutations 这四巨头 我们可以轻松使用命名空间 这里不做过多讲解，实战课程中我们边用边说。</p>

        </div>

        
<div class="post-archive">
    <ul class="post-copyright">
        <li><strong>原文作者：</strong><a rel="author" href="https://luckly.work/">luckly</a></li>
        <li style="word-break:break-all"><strong>原文链接：</strong><a href="https://luckly.work/post/vue/Vue_cli%E7%9B%B8%E5%85%B3vuex%E4%BB%A5%E5%8F%8ARouter/">https://luckly.work/post/vue/Vue_cli%E7%9B%B8%E5%85%B3vuex%E4%BB%A5%E5%8F%8ARouter/</a></li>
        <li><strong>版权声明：</strong>本作品采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议</a>进行许可，非商业转载请注明出处（作者，原文链接），商业转载请联系作者获得授权。</li>
    </ul>
</div>
<br/>



        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/post/vue/Vue%E6%9E%84%E9%80%A0%E6%9C%9F%E5%86%85%E5%B8%B8%E7%94%A8%E5%B1%9E%E6%80%A7/">Vue构造期内常用属性</a></li>
        
        <li><a href="/post/vue/Vue%E7%BB%84%E4%BB%B6%E5%BC%80%E5%8F%91%E4%BB%A5%E5%8F%8A%E5%B8%B8%E7%94%A8%E5%85%A8%E5%B1%80api/">Vue组件开发以及常用全局api</a></li>
        
        <li><a href="/post/vue/Vue.js%E7%9A%84%E8%B5%B7%E6%AD%A5/">Vue.js 起步</a></li>
        
        <li><a href="/post/vue/Vue.js%E7%9A%84%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84/">Vue.js 目录结构</a></li>
        
        <li><a href="/post/vue/Vue.js%E7%9A%84%E5%AE%89%E8%A3%85/">Vue.js 安装</a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='/tags/Vue'>Vue</a></li>
                
            </ul>
            
        </div>
    </article>
    
    

    
    
    <div class="post bg-white">
      <script src="https://utteranc.es/client.js"
            repo= "https://github.com/ITmxs/repo"
            issue-term="pathname"
            theme="github-light"
            crossorigin="anonymous"
            async>
      </script>
    </div>
    
</div>

                    <footer id="footer">
    <div>
        &copy; 2021 <a href="https://luckly.work/">早起的年轻人 By luckly</a>
        
        | <a rel="nofollow" target="_blank" href="http://beian.miit.gov.cn/">粤ICP备2021号-1</a>
        
    </div>
    <br />
    <div>
        <div class="github-badge">
            <a href="https://juejin.cn/user/3843548384077192" target="_black" rel="nofollow"><span class="badge-subject">Powered by</span><span class="badge-value bg-blue">掘金</span></a>
        </div>
        <div class="github-badge">
            <a href="https://space.bilibili.com/480883651" target="_black"><span class="badge-subject">Design by</span><span class="badge-value bg-brightgreen">早起的年轻人</span></a>
        </div>
        <div class="github-badge">
            <a href="https://cloud.tencent.com/developer/user/6702670" target="_black"><span class="badge-subject">Theme</span><span class="badge-value bg-yellowgreen">云社区</span></a>
        </div>
    </div>
</footer>


    
    <script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script><script src="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/js/totop.js?v=0.0.0' async=""></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/js/douban.js'></script>
    <script src="/js/copy-to-clipboard.js"></script>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://luckly.work/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://luckly.work/">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://luckly.work/post/nginx/nginx%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9/" title="Nginx文件内容">Nginx文件内容</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/nginx/nginx%E6%9E%81%E7%AE%80%E6%95%99%E7%A8%8B/" title="Nginx极简教程">Nginx极简教程</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/nginx/%E5%8D%81%E5%88%86%E9%92%9F%E5%85%A5%E9%97%A8nginx/" title="十分钟入门Nginx">十分钟入门Nginx</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/go/Goland%E8%BF%9C%E7%A8%8B%E5%BC%80%E5%8F%91%E9%85%8D%E7%BD%AE/" title="Goland远程开发配置">Goland远程开发配置</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/%E8%AF%BB%E4%B9%A6/%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90/" title="域名解析">域名解析</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/git/%E6%8F%90%E4%BA%A4%E8%BF%87%E7%A8%8B%E7%9C%81%E7%95%A5%E6%9F%90%E4%BA%9B%E6%96%87%E4%BB%B6/" title="提交过程省略某些文件">提交过程省略某些文件</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter_DropdownButton%E7%A4%BA%E4%BE%8B/" title="Flutter_DropdownButton示例">Flutter_DropdownButton示例</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter_ExpansionPanelList%E5%92%8CExpansionPanelList.radio%E7%A4%BA%E4%BE%8B/" title="Flutter_ExpansionPanelList和ExpansionPanelList">Flutter_ExpansionPanelList和ExpansionPanelList</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter%E5%BE%AE%E4%BF%A1%E5%88%86%E4%BA%AB%E9%93%BE%E6%8E%A5%E8%B7%B3%E5%9B%9EApp%E6%8C%87%E5%AE%9A%E9%A1%B5%E9%9D%A2/" title="Flutter微信分享链接跳回App指定页面">Flutter微信分享链接跳回App指定页面</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F/%E5%A4%96%E5%8C%85%E5%8F%AF%E8%83%BD%E7%9A%84%E9%97%AE%E9%A2%98/" title="外包可能的问题">外包可能的问题</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title"><a href='/categories/'>分类</a></h3>
<ul class="widget-list">
    
    <li><a href="https://luckly.work/categories/Flutter/">Flutter (326)</a></li>
    
    <li><a href="https://luckly.work/categories/IT/">IT (2)</a></li>
    
    <li><a href="https://luckly.work/categories/Kotlin/">Kotlin (2)</a></li>
    
    <li><a href="https://luckly.work/categories/Mysql/">Mysql (1)</a></li>
    
    <li><a href="https://luckly.work/categories/nginx/">nginx (1)</a></li>
    
    <li><a href="https://luckly.work/categories/Vue/">Vue (6)</a></li>
    
    <li><a href="https://luckly.work/categories/YouTube%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD/">YouTube视频下载 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/android/">android (6)</a></li>
    
    <li><a href="https://luckly.work/categories/dart/">dart (96)</a></li>
    
    <li><a href="https://luckly.work/categories/Flutter/">Flutter (28)</a></li>
    
    <li><a href="https://luckly.work/categories/gin/">gin (25)</a></li>
    
    <li><a href="https://luckly.work/categories/git/">git (4)</a></li>
    
    <li><a href="https://luckly.work/categories/Go/">Go (102)</a></li>
    
    <li><a href="https://luckly.work/categories/gorm/">gorm (4)</a></li>
    
    <li><a href="https://luckly.work/categories/grpc/">grpc (1)</a></li>
    
    <li><a href="https://luckly.work/categories/html/">html (3)</a></li>
    
    <li><a href="https://luckly.work/categories/ios/">ios (1)</a></li>
    
    <li><a href="https://luckly.work/categories/linux/">linux (1)</a></li>
    
    <li><a href="https://luckly.work/categories/nginx/">nginx (6)</a></li>
    
    <li><a href="https://luckly.work/categories/python/">python (35)</a></li>
    
    <li><a href="https://luckly.work/categories/read/">读书笔记 (6)</a></li>
    
    <li><a href="https://luckly.work/categories/redis/">redis (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99/">个人资料 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B9%A6%E5%8D%95/">书单 (8)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B9%A6%E8%AF%84/">书评 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统管理师 (19)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统项目管理师 (25)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%8E%9F%E5%88%99/">原则 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%8E%9F%E7%94%9F%E9%80%9A%E8%AE%AF/">原生通讯 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%9F%BA%E7%A1%80/">基础 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%A4%8D%E5%88%A9%E6%95%88%E5%BA%94/">复利效应 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">安装教程 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%B0%91%E6%9C%89%E4%BA%BA%E8%B5%B0%E7%9A%84%E8%B7%AF/">少有人走的路 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%BF%83%E8%AF%AD/">心语 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E6%8F%92%E4%BB%B6/">插件 (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E6%95%99%E5%AD%A6/">教学 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%8E%8B%E9%98%B3%E6%98%8E/">王阳明 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%94%B5%E5%AD%90%E4%B9%A6/">电子书 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%99%BB%E9%99%86%E8%A1%A8%E5%8D%95/">登陆表单 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%A8%BB%E7%9B%9B%E5%92%8C%E5%A4%AB/">稻盛和夫 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%A9%B7%E7%88%B8%E7%88%B8%E5%AF%8C%E7%88%B8%E7%88%B8/">穷爸爸富爸爸 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%B2%BE%E8%BF%9B/">精进 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%BC%96%E7%A8%8B/">编程 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%99%9A%E5%B9%BB/">虚幻 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B4%A2%E5%8A%A1%E8%87%AA%E7%94%B1%E4%B9%8B%E8%B7%AF/">财务自由之路 (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%91%E6%AD%A5/">跑步 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%AF%E7%94%B1%E4%BC%A0%E5%8F%82/">路由传参 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%AF%E7%BA%BF/">路线 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%BD%AF%E4%BB%B6%E5%AE%9E%E6%96%BD/">软件实施 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%98%B3%E6%98%8E%E5%BF%83%E5%AD%A6/">阳明心学 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%A1%B9%E7%9B%AE/">项目 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%AD%85%E5%8A%9B/">魅力 (1)</a></li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title"><a href='/tags/'>标签</a></h3>
<div class="tagcloud">
    
    <a href="https://luckly.work/tags/flutter/">flutter</a>
    
    <a href="https://luckly.work/tags/IT/">IT</a>
    
    <a href="https://luckly.work/tags/Kotlin/">Kotlin</a>
    
    <a href="https://luckly.work/tags/Mysql/">Mysql</a>
    
    <a href="https://luckly.work/tags/nginx/">nginx</a>
    
    <a href="https://luckly.work/tags/Vue/">Vue</a>
    
    <a href="https://luckly.work/tags/YouTube%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD/">YouTube视频下载</a>
    
    <a href="https://luckly.work/tags/android/">android</a>
    
    <a href="https://luckly.work/tags/dart/">dart</a>
    
    <a href="https://luckly.work/tags/flutter/">flutter</a>
    
    <a href="https://luckly.work/tags/gin/">gin</a>
    
    <a href="https://luckly.work/tags/git/">git</a>
    
    <a href="https://luckly.work/tags/go/">go</a>
    
    <a href="https://luckly.work/tags/gorm/">gorm</a>
    
    <a href="https://luckly.work/tags/grpc/">grpc</a>
    
    <a href="https://luckly.work/tags/html/">html</a>
    
    <a href="https://luckly.work/tags/ios/">ios</a>
    
    <a href="https://luckly.work/tags/linux/">linux</a>
    
    <a href="https://luckly.work/tags/nginx/">nginx</a>
    
    <a href="https://luckly.work/tags/python/">python</a>
    
    <a href="https://luckly.work/tags/redis/">redis</a>
    
    <a href="https://luckly.work/tags/%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99/">个人资料</a>
    
    <a href="https://luckly.work/tags/%E4%B9%A6%E5%8D%95/">书单</a>
    
    <a href="https://luckly.work/tags/%E4%B9%A6%E8%AF%84/">书评</a>
    
    <a href="https://luckly.work/tags/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统管理师</a>
    
    <a href="https://luckly.work/tags/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统项目管理师</a>
    
    <a href="https://luckly.work/tags/%E5%85%A5%E9%97%A8/">入门</a>
    
    <a href="https://luckly.work/tags/%E5%8E%9F%E5%88%99/">原则</a>
    
    <a href="https://luckly.work/tags/%E5%8E%9F%E7%94%9F%E9%80%9A%E8%AE%AF/">原生通讯</a>
    
    <a href="https://luckly.work/tags/%E5%9F%BA%E7%A1%80/">基础</a>
    
    <a href="https://luckly.work/tags/%E5%A4%8D%E5%88%A9%E6%95%88%E5%BA%94/">复利效应</a>
    
    <a href="https://luckly.work/tags/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">安装教程</a>
    
    <a href="https://luckly.work/tags/%E5%B0%91%E6%9C%89%E4%BA%BA%E8%B5%B0%E7%9A%84%E8%B7%AF/">少有人走的路</a>
    
    <a href="https://luckly.work/tags/%E5%BF%83%E8%AF%AD/">心语</a>
    
    <a href="https://luckly.work/tags/%E6%8F%92%E4%BB%B6/">插件</a>
    
    <a href="https://luckly.work/tags/%E6%95%99%E5%AD%A6/">教学</a>
    
    <a href="https://luckly.work/tags/%E7%8E%8B%E9%98%B3%E6%98%8E/">王阳明</a>
    
    <a href="https://luckly.work/tags/%E7%94%B5%E5%AD%90%E4%B9%A6/">电子书</a>
    
    <a href="https://luckly.work/tags/%E7%99%BB%E9%99%86%E8%A1%A8%E5%8D%95/">登陆表单</a>
    
    <a href="https://luckly.work/tags/%E7%A8%BB%E7%9B%9B%E5%92%8C%E5%A4%AB/">稻盛和夫</a>
    
    <a href="https://luckly.work/tags/%E7%A9%B7%E7%88%B8%E7%88%B8%E5%AF%8C%E7%88%B8%E7%88%B8/">穷爸爸富爸爸</a>
    
    <a href="https://luckly.work/tags/%E7%B2%BE%E8%BF%9B/">精进</a>
    
    <a href="https://luckly.work/tags/%E7%BC%96%E7%A8%8B/">编程</a>
    
    <a href="https://luckly.work/tags/%E8%99%9A%E5%B9%BB/">虚幻</a>
    
    <a href="https://luckly.work/tags/%E8%AF%97/">诗</a>
    
    <a href="https://luckly.work/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/">读书笔记</a>
    
    <a href="https://luckly.work/tags/%E8%B4%A2%E5%8A%A1%E8%87%AA%E7%94%B1%E4%B9%8B%E8%B7%AF/">财务自由之路</a>
    
    <a href="https://luckly.work/tags/%E8%B7%91%E6%AD%A5/">跑步</a>
    
    <a href="https://luckly.work/tags/%E8%B7%AF%E7%94%B1%E4%BC%A0%E5%8F%82/">路由传参</a>
    
    <a href="https://luckly.work/tags/%E8%B7%AF%E7%BA%BF/">路线</a>
    
    <a href="https://luckly.work/tags/%E8%BD%AF%E4%BB%B6%E5%AE%9E%E6%96%BD/">软件实施</a>
    
    <a href="https://luckly.work/tags/%E9%80%9A%E8%AE%AF%E5%BD%95/">通讯录</a>
    
    <a href="https://luckly.work/tags/%E9%98%B3%E6%98%8E%E5%BF%83%E5%AD%A6/">阳明心学</a>
    
    <a href="https://luckly.work/tags/%E9%A1%B9%E7%9B%AE/">项目</a>
    
    <a href="https://luckly.work/tags/%E9%AD%85%E5%8A%9B/">魅力</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="http://www.topgoer.com/" title="枯藤">枯藤</a>
        </li>
        
        <li>
            <a target="_blank" href="https://gorm.cn/zh_CN/docs/index.html" title="gorm">gorm</a>
        </li>
        
        <li>
            <a target="_blank" href="https://docs.python.org/zh-cn/3/tutorial/index.html" title="python">python</a>
        </li>
        
        <li>
            <a target="_blank" href="https://www.liwenzhou.com/" title="李文周">李文周的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="http://www.xbzweb.com/" title="小包子的博客">小包子的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://www.flysnow.org/" title="飞雪无情的博客">飞雪无情的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://sliverhorn.com/" title="sliverhorn的博客">sliverhorn的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="http://yuedu.baidu.com/ebook/14a722970740be1e640e9a3e" title="Android Gradle权威指南">Android Gradle权威指南</a>
        </li>
        
        <li>
            <a target="_blank" href="https://gesdh.cn/" title="小格子">格子导航</a>
        </li>
        
        <li>
            <a target="_blank" href="https://itachi.xyz/" title="阿林">itachi&#39;s Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="https://darjun.github.io/" title="大俊">大俊Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="https://geektutu.com/post/quick-golang.html" title="极客兔兔">极客兔兔Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="http://zxfcumtcs.github.io/" title="赵雪峰">雪峰Blog</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://luckly.work/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
</body>

</html>